<style lang="less">
    @import "./main.less";
</style>
<template>
    <div class="main" :class="{'main-hide-text': shrink}">
        <div class="main-header-con custom-main-header"><!-- :style="{paddingLeft: shrink?'80px':'256px'}"> -->
            <div class="main-header" style="background:#4b97ff">
                <div>
                  <a @click="gotoHome" class="header-brand" style="height: 60px;display: flex;align-items: center;">
                    <img src="../images/houtailogo.png" style="width:45px;height:45px;margin-right:10px">
                    <h1 style="letter-spacing:1px">{{L('AppName')}}</h1>
                  </a>
                </div>
                <div class="navicon-con">
                    <Button :style="{transform: 'rotateZ(' + (this.shrink ? '-90' : '0') + 'deg)'}" type="text" @click="toggleClick">
                        <Icon type="navicon" size="32"></Icon>
                    </Button>
                </div>
                <!-- <div class="header-middle-con">
                    <div class="main-breadcrumb">
                        <breadcrumb-nav :currentPath="currentPath"></breadcrumb-nav>
                    </div>
                </div> -->
                <div class="header-avator-con">
                    <!-- <full-screen v-model="isFullScreen" @on-change="fullscreenChange"></full-screen> -->
                    <!-- <lock-screen></lock-screen>   -->
                    <!-- <notice></notice>    -->
                    <!-- <language-list></language-list>          -->
                    <div class="ivu-row-flex ivu-row-flex-middle" style="height:100%">
                    </div>
                    <div class="user-dropdown-menu-con">
                        <Row type="flex" justify="end" align="middle" class="user-dropdown-innercon">
                            <Dropdown transfer trigger="click" @on-click="handleClickUserDropdown">
                                <a href="javascript:void(0)">
                                    <span class="main-user-name">{{ userName }}</span>
                                    <Icon type="md-arrow-dropdown" />
                                </a>
                                <DropdownMenu slot="list">
                                    <DropdownItem name="ownSpace">{{L('UserProfile')}}</DropdownItem>
                                    <DropdownItem name="loginout" divided>{{L('Logout')}}</DropdownItem>
                                </DropdownMenu>
                            </Dropdown>
                            <span class="avatar" style="background: #619fe7;margin-left: 10px;"><img src="../images/usericon.jpg" /></span>
                        </Row>
                    </div>
                </div>
            </div>
            <div class="tags-con" :style="{paddingLeft: shrink?'80px':'256px'}">
                <tags-page-opened :pageTagsList="pageTagsList"></tags-page-opened>
            </div>
        </div>
      
        <div>
          <div class="sidebar-menu-con custom-sidebar-menu" :style="{width: shrink?'80px':'256px', overflow: shrink ? 'visible' : 'auto'}">
              <shrinkable-menu 
                  :shrink="shrink"
                  @on-change="handleSubmenuChange"
                  :theme="menuTheme" 
                  :before-push="beforePush"
                  :open-names="openedSubmenuArr"
                  :menu-list="menuList">
                  <!-- <div slot="top" class="logo-con">
                    <a>
                      <Icon type="cube" size="32"></Icon>
                      <h1 >{{L('AppName')}}</h1>
                    </a>
                    
                  </div> -->
              </shrinkable-menu>
          </div>
          
          <div class="single-page-con" :style="{left: shrink?'80px':'256px'}">
              <div class="single-page">
                  <keep-alive :include="cachePage">
                      <router-view></router-view>
                  </keep-alive>                
              </div>
              <copyfooter :copyright="L('CopyRight')"></copyfooter>
          </div>
        </div>
        
    </div>
</template>
<script lang="ts">
    import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';
    import shrinkableMenu from '../components/shrinkable-menu/shrinkable-menu.vue';
    import tagsPageOpened from '../components/tags-page-opened.vue';
    import breadcrumbNav from '../components/breadcrumb-nav.vue';
    import fullScreen from '../components/fullscreen.vue';
    import lockScreen from '../components/lockscreen/lockscreen.vue';
    import notice from '../components/notices/notice.vue';
    import util from '../lib/util';
    import copyfooter from '../components/Footer.vue';
    import LanguageList from '../components/language-list.vue';
    import AbpBase from '../lib/abpbase';
    import appconsts from '@/lib/appconst'

    @Component({
      components:{shrinkableMenu,tagsPageOpened,breadcrumbNav,fullScreen,lockScreen,notice,copyfooter,LanguageList}
    })
    export default class Main extends AbpBase {
        shrink:boolean=false;
        get userName(){
          return this.$store.state.session.user?this.$store.state.session.user.name:''
        }
        isFullScreen:boolean=false;
        messageCount:string='0';

        get openedSubmenuArr(){
          return this.$store.state.app.openedSubmenuArr
        }
        get menuList () {
          return this.$store.state.app.menuList;
        }
        get pageTagsList () {
          return this.$store.state.app.pageOpenedList as Array<any>;
        }
        get currentPath () {
          return this.$store.state.app.currentPath;
        }
        get lang(){
          return this.$store.state.app.lang;
        }
        get avatorPath () {
          return localStorage.avatorImgPath;
        }
        get cachePage () {
          return this.$store.state.app.cachePage;
        }
        get menuTheme () {
          return this.$store.state.app.menuTheme;
        }
        get mesCount () {
          return this.$store.state.app.messageCount;
        }
        init () {
          let pathArr = util.setCurrentPath(this, this.$route.name as string);
          this.$store.commit('app/updateMenulist');
          if (pathArr.length >= 2) {
            this.$store.commit('app/addOpenSubmenu', pathArr[1].name);
          }
          let messageCount = 3;
          this.messageCount = messageCount.toString();
          this.checkTag(this.$route.name);
        }
        toggleClick () {
          this.shrink = !this.shrink;
        }
        handleClickUserDropdown (name:string) {
          if (name === 'ownSpace') {
            util.openNewPage(this, 'ownspace_index',null,null);
            this.$router.push({
              name: 'ownspace_index'
            });
          } else if (name === 'loginout') {
            this.$store.commit('app/logout', this);
            util.abp.auth.clearToken();
            location.reload();
          }
        }
        checkTag (name?:string) {
          let openpageHasTag = this.pageTagsList.some((item:any) => {
            if (item.name === name) {
              return true;
            }else{
              return false
            }
          });
          if (!openpageHasTag) { 
            util.openNewPage(this, name as string, this.$route.params || {}, this.$route.query || {});
          }
        }
        handleSubmenuChange (val:string) {
          // console.log(val)
        }
        beforePush (name:string) {
          if (name === 'accesstest_index') {
            return false;
          } else {
            return true;
          }
        }
        fullscreenChange (isFullScreen:boolean) {
                // console.log(isFullScreen);
        }
        @Watch('$route')
        routeChange(to:any){
          this.$store.commit('app/setCurrentPageName', to.name);
          let pathArr = util.setCurrentPath(this, to.name);
          if (pathArr.length > 2) {
            this.$store.commit('app/addOpenSubmenu', pathArr[1].name);
          }
          this.checkTag(to.name);
          localStorage.currentPageName = to.name;
        }
        @Watch('lang')
        langChange(){
          util.setCurrentPath(this, this.$route.name as string);
        }
        mounted () {
            this.init();
        }
        created () {
            this.$store.commit('app/setOpenedList');
			const isSet = parseInt(abp.utils.getCookieValue('Abp.isSet'));
			console.log('isSet',typeof('isSet'));
			if(isSet && isSet === 1){
				this.$Modal.warning({
					title: "温馨提示",
					content: "您的密码过于简单，请立即修改密码！",
					onOk: async () => {
					  const curWwwPath=window.document.location.href;
					  //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
					  const pathName=window.document.location.pathname;      
					  const pos=curWwwPath.indexOf(pathName);      
					  //获取主机地址，如： http://localhost:8083
					  const localhostPaht=curWwwPath.substring(0,pos); 
					  
					  const url = localhostPaht + '/html/change_password.html?from=manage';
					  // this.$router.push({path: url});
					  window.document.location.href = url;
					  // window.open('http://pingjia.laotingedu.cn/html/change_password.html');
					}
				});
			}
			 
			
			
        }

        // ----- methods -----
        gotoHome() {
		  const curWwwPath=window.document.location.href;      
		  //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
		  const pathName=window.document.location.pathname;      
		  const pos=curWwwPath.indexOf(pathName);      
		  //获取主机地址，如： http://localhost:8083
		  const localhostPaht=curWwwPath.substring(0,pos); 
		  const url = localhostPaht + '/html';
		  // this.$router.push({path: url});
		  window.open(url);
        }
        gotoHelp() {
          console.log('go to help -----')
        }
    }
</script>

<style lang="less">
.custom-main-header {
  padding-left: 0;
  
  .main-header {
    background: #2268C7;
    overflow: hidden;

    .header-avator-con .user-dropdown-menu-con {
      width: 136px;
    }
  }

  .ivu-btn-text {
    color: #FFFFFF;
  }

  a {
    color: #FFFFFF;
  }
}
.main .sidebar-menu-con{
	background:#001529;
}
.main .sidebar-menu-con.custom-sidebar-menu {
  top: 60px;
  right: 0;
  bottom: 0;
  overflow: auto;
  padding-bottom: 60px;
}
.header-brand {
  padding-left: 12px;

  & > .ivu-icon,
  & > h1 {
    line-height: 60px;
    display: inline-block;
    vertical-align: middle;
    color: #FFF;
  }
}
.ivu-shrinkable-menu{
	height:auto;
}
.mr-2 {
  margin-right: 10px;
}
.waitingMsg {
	color: transparent;
	font-size: 18px;
}
.waitingMsg:first-child {
	color: #000000;
}
</style>